﻿//////////////////////////////////////////////////////////////////////
#pragma once

#include <atlctrls.h>
#include <atlmisc.h>

#include <Gdiplus.h>
using namespace Gdiplus;
#pragma comment(lib, "Gdiplus.lib")

#include "BackGDC.h"

using namespace ATL;
#define CTRL_TM_RADIOBOX_ANIM	20110905

class CDUIRadioBox :public CWindowImpl<CDUIRadioBox, CButton>,
					public COwnerDraw<CDUIRadioBox>
{
public:
	CDUIRadioBox();
	~CDUIRadioBox();
public:
	BEGIN_MSG_MAP_EX(CDUIRadioBox)
		MSG_WM_LBUTTONDOWN(OnLButtonDown)
		MSG_WM_LBUTTONUP(OnLButtonUp)
		MSG_WM_MOUSEMOVE(OnMouseMove)
		MSG_WM_MOUSELEAVE(OnMouseLeave)
		MESSAGE_HANDLER(WM_TIMER, OnTimer)
		MESSAGE_HANDLER(BM_GETCHECK, OnGetCheck)
		MESSAGE_HANDLER(BM_SETCHECK, OnSetCheck)
		MESSAGE_HANDLER(WM_ERASEBKGND, OnEraseBkgnd)
		MSG_WM_ENABLE(OnEnable)
		CHAIN_MSG_MAP_ALT(COwnerDraw<CDUIRadioBox >, 1)
		DEFAULT_REFLECTION_HANDLER()
	END_MSG_MAP()
public:
	void	OnLButtonDown(UINT nFlags, CPoint pt);
	void	OnLButtonUp(UINT nFlags, CPoint point);
	void	OnMouseMove(UINT nFlags, CPoint point);
	void	OnMouseLeave();
	LRESULT OnGetCheck(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnSetCheck(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT OnEraseBkgnd(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	LRESULT	OnTimer(UINT uMsg, WPARAM wParam, LPARAM lParam, BOOL& bHandled);
	void	DrawItem(LPDRAWITEMSTRUCT lpdis);
	void	MeasureItem(LPMEASUREITEMSTRUCT lpMeasureItemStruct);
	void	OnEnable(BOOL bEnable);
public:
	BOOL	SubclassWindow(HWND hwnd);
	int		GetCheck();
	void	SetCheck(int nstatus);
	void	SetTextColor(COLORREF color, COLORREF colorDis = RGB(160,160,160));
	void	GetTextColor(COLORREF& color, COLORREF& colorDis);
	void	SetTransparentBK(BOOL bTrans = TRUE);
	void	SetAnimationState(BOOL bState);
	BOOL	GetAnimationState();
private:
	void	_DrawCtrl(HDC hdc, BOOL IsCheck, emCtrlState m_emState);
	void	_ReaderAnimation();
	void	_CloseFadeAnimation();
private:
	emCtrlState m_emState;
	emCtrlState m_emOldState;
	bool		m_bIsCheck;
	BOOL		m_bTracking;
	bool		m_bCheckedChg;

	COLORREF	m_clTextNormal;
	COLORREF	m_clTextDisable;
	BOOL		m_bTransBK;

	BackGDC *	m_pBackUpDC;
	BackGDC *	m_pReaderDC;
	RECT		m_rcRect;
	Gdiplus::Image * m_pImage;
	BOOL		m_bIsFirst;
//Animation
	BOOL		m_IsOpenAnim;
	long		m_ltmAnimation;
	double		m_nAlpha;
	int			m_nIndex;
	BOOL		m_bIsFading;
};